package soft.edu.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import soft.edu.common.Const;
import soft.edu.common.ServerResponse;
import soft.edu.pojo.*;
import soft.edu.service.*;

import java.util.List;

@Controller
@RequestMapping("/sch/")
public class SchoolController {

    //自动装配，不用new。spring
    @Autowired
    private SchExamAreaService schExamAreaService;
    @Autowired
    private SchMajorCatalogService schMajorCatalogService;
    @Autowired
    private SchRecruitPageService schRecruitPageService;
    @Autowired
    private SchResearchDirectionService schResearchDirectionService;
    @Autowired
    private SchScoreLevelService schScoreLevelService;
    @Autowired
    private SchUniversityService schUniversityService;


//    返回考试范围信息
    @RequestMapping(value = "renderExaList.do",method = RequestMethod.GET)
    @ResponseBody
    public List<SchExamArea> renderExaList(String year,String exa_uni_name, String exa_college_name, String exa_maj_name) {
        if(year == null){
            year = Const.SCH_DEFAULT_YEAR;
        }
        ServerResponse<List<SchExamArea>> response = schExamAreaService.getInfo(year,exa_uni_name, exa_college_name, exa_maj_name);
        return response.getData();
//        return schExamAreaService.getInfo(exa_uni_name, exa_college_name, exa_maj_name);
    }


    //根据院校名称获取所有专业信息
    @RequestMapping(value = "renderMajListbyUniname.do",method = RequestMethod.GET)
    @ResponseBody
    public List<SchMajorCatalog> renderMajListbyUniname(String year, String maj_uni_name,String maj_college_name, String maj_name){
        if(year == null){
            year = Const.SCH_DEFAULT_YEAR;
        }
        ServerResponse<List<SchMajorCatalog>> response = schMajorCatalogService.getInfo(year,maj_uni_name, maj_college_name, maj_name);
        return response.getData();
    }


//    返回所查询学校的院系列表
    @RequestMapping(value = "renderCollege.do",method = RequestMethod.GET)
    @ResponseBody
    public List<String> renderCollege(String maj_uni_name){
        ServerResponse<List<String>> response = schMajorCatalogService.getCollege(maj_uni_name);
        return response.getData();
    }


    //    返回所查询学校的专业列表
    @RequestMapping(value = "renderMajor.do",method = RequestMethod.GET)
    @ResponseBody
    public List<String> renderMajor(String maj_uni_name){
        ServerResponse<List<String>> response = schMajorCatalogService.getMajor(maj_uni_name);
        return response.getData();
    }


//    根据学科类型返回对应的专业目录(有学科评估等级)
    @RequestMapping(value = "renderMajbySubject.do",method = RequestMethod.GET)
    @ResponseBody
    public List<String> renderMajbySubject(String maj_subject){
        ServerResponse<List<String>> response = schMajorCatalogService.getMajorwithSubject(maj_subject);
        return response.getData();
    }


//    根据院校名称获取招生简章信息
    @RequestMapping(value = "renderRecListbyUniname.do",method = RequestMethod.GET)
    @ResponseBody
    public List<SchRecruitPage> renderRecListbyUniname(String year,String rec_uni_name){
        //如果没有年份输入，则年份设为默认年
        if(year==null){
            year = Const.SCH_DEFAULT_YEAR;
        }
        ServerResponse<List<SchRecruitPage>> response = schRecruitPageService.getInfo(year,rec_uni_name);
        return response.getData();
    }


    //    根据院校、学院、专业查研究方向的信息
    @RequestMapping(value = "renderRDList.do",method = RequestMethod.GET)
    @ResponseBody
    public List<SchResearchDirection> renderRDList(String year, String res_uni_name, String res_college_name, String res_maj_name){
        if(year == null){
            year = Const.SCH_DEFAULT_YEAR;
        }
        ServerResponse<List<SchResearchDirection>> response = schResearchDirectionService.getRDInfo(year, res_uni_name, res_college_name, res_maj_name);
        return response.getData();
    }


// 根据年份等信息返回某个院校专业的报录信息
//    renderREList_Detail的优化版，只根据年份和院校查询，不用院校名和专业名
    @RequestMapping(value = "renderREList.do",method = RequestMethod.GET)
    @ResponseBody
    public List<SchResearchDirection> renderREList(String year,String res_uni_name){
//        如果查询时，没有年份要求，则查询默认年份的数据
        if(year==null){
            year = Const.SCH_DEFAULT_YEAR;
        }
        ServerResponse<List<SchResearchDirection>> response = schResearchDirectionService.getRD_byYear(year, res_uni_name, null, null);
        return response.getData();
    }


// 根据年份等信息返回某个院校专业的报录信息
    @RequestMapping(value = "renderREList_Detail.do",method = RequestMethod.GET)
    @ResponseBody
    public List<SchResearchDirection> renderREList_Detail(String res_year,String res_uni_name, String res_college_name, String res_maj_name){
        ServerResponse<List<SchResearchDirection>> response = schResearchDirectionService.getRD_byYear(res_year, res_uni_name, res_college_name, res_maj_name);
        return response.getData();
    }


    //根据院校名查分数信息
    @RequestMapping(value = "renderScoList.do",method = RequestMethod.GET)
    @ResponseBody
    public List<SchScoreLevel> renderScoList(String year, String sco_uni_name, String sco_college_name, String sco_maj_name){
        if(year == null){
            year = Const.SCH_DEFAULT_YEAR;
        }
        ServerResponse<List<SchScoreLevel>> response = schScoreLevelService.getInfo(year,sco_uni_name, sco_college_name, sco_maj_name);
        return response.getData();
    }


    //    返回所有院校列表
    @RequestMapping(value = "renderUniList.do",method = RequestMethod.GET)
    @ResponseBody
    public List<SchUniversity> renderUniList(){
        ServerResponse<List<SchUniversity>> response = schUniversityService.getAll();
        return response.getData();
    }


    //    根据搜索框查找信息
    @RequestMapping(value = "renderUniListbySearch.do",method = RequestMethod.GET)
    @ResponseBody
    public List<SchUniversity> renderUniListbySearch(String keywords){
        ServerResponse<List<SchUniversity>> response = schUniversityService.getAllbySearch(keywords);
        return response.getData();
    }


    //根据条件筛选信息
    @RequestMapping(value = "renderUniListbyFiltrate.do",method = RequestMethod.GET)
    @ResponseBody
    public List<SchUniversity> renderUniListbyFiltrate(String city, String is_211, String is_985, String is_graduate_school, String is_self_line){
        ServerResponse<List<SchUniversity>> response = schUniversityService.getAllbyFiltrate(city, is_211, is_985, is_graduate_school, is_self_line);
        return response.getData();
    }


//    返回根据专业检索后的院校信息
    @RequestMapping(value = "renderUniAndMaj.do",method = RequestMethod.GET)
    @ResponseBody
    public List<SchUniAndMaj> renderUniAndMaj(String maj_name){
        ServerResponse<List<SchUniAndMaj>> response = schUniversityService.getInfoByUniAndMaj(maj_name);
        return response.getData();
    }
}
